package com.desuntech.utils
{
	public class DateUtils
	{
		// Date parts
		public static const YEAR:String		= "fullYear";
		public static const MONTH:String	= "month";
		public static const WEEK:String		= "week";
		public static const DAY_OF_MONTH:String	= "date";
		public static const HOURS:String	= "hours";
		public static const MINUTES:String	= "minutes";
		public static const SECONDS:String	= "seconds";
		public static const MILLISECONDS:String	= "milliseconds";
		public static const DAY_OF_WEEK:String	= "day";
		
		/**
		 * Adds the specified number of "date parts" to a date, e.g. 6 days
		 * 
		 * @param datePart	The part of the date that will be added
		 * @param number	The total number of "dateParts" to add to the date
		 * @param date		The date on which to add
		 * 
		 * @return			The new date
		 */
		public static function dateAdd( datePart:String, number:Number, date:Date ):Date {
			var _returnDate:Date = new Date( date );
			
			switch ( datePart ) {
				case DateUtils.YEAR:
				case DateUtils.MONTH:
				case DateUtils.DAY_OF_MONTH:
				case DateUtils.HOURS:
				case DateUtils.MINUTES:
				case DateUtils.SECONDS:
				case DateUtils.MILLISECONDS:
					_returnDate[ datePart ] += number;
					break;
				case DateUtils.WEEK:
					_returnDate[ DateUtils.DAY_OF_MONTH ] += number * 7;
					break;
				default:
					/* Unknown date part, do nothing. */
					break;
			}
			return _returnDate;
		}
	}
}